package com.duowei.diandan.callback;

import android.support.v7.util.DiffUtil;

import com.duowei.diandan.bean.food.FoodImpl;

import java.util.List;
import java.util.Objects;

public class FoodImplDiffCallback extends DiffUtil.Callback {

    private final List<? extends FoodImpl> mOldList;
    private final List<? extends FoodImpl> mNewList;

    public FoodImplDiffCallback(List<? extends FoodImpl> oldList, List<? extends FoodImpl> newList) {
        mOldList = oldList;
        mNewList = newList;
    }

    @Override
    public int getOldListSize() {
        return mOldList.size();
    }

    @Override
    public int getNewListSize() {
        return mNewList.size();
    }

    @Override
    public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
        FoodImpl oldFood = mOldList.get(oldItemPosition);
        FoodImpl newFood = mNewList.get(newItemPosition);

        return Objects.equals(oldFood.getImgNo(), newFood.getImgNo());
    }

    @Override
    public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
        FoodImpl oldFood = mOldList.get(oldItemPosition);
        FoodImpl newFood = mNewList.get(newItemPosition);
        return Objects.equals(oldFood, newFood);
    }
}
